package com.ckx.test;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class GIthub {

    public static void main(String[] args) throws InterruptedException {

        ReentrantLock lock = new ReentrantLock();

        lock.unlock();

        ExecutorService executorService = Executors.newFixedThreadPool(1);
        ArrayBlockingQueue queue = new ArrayBlockingQueue(20);

        executorService.execute( () -> {
            for (;;) {
                try {
                    queue.take();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread.sleep(3000);
        executorService.shutdown();
        System.out.println("shutdown");
        executorService.awaitTermination(2, TimeUnit.SECONDS);

        /*String s = HttpUtil.get("https://api.github.com/meta");
        System.out.println(JSONUtil.toJsonPrettyStr(s));

        JSONObject entries = JSONUtil.parseObj(s);
        JSONArray packages = entries.getJSONArray("git");
        List<String> packageList = packages.toList(String.class);
        List<String> ipList = packageList.stream()
                .map(item -> StringUtils.split(item, "/")[0])
                .collect(Collectors.toList());

        String url = "https://{ip}:443/";

        ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();

        RequestConfig config = RequestConfig.custom()
                .setConnectTimeout(3000)
                .build();

        CloseableHttpClient client = HttpClientBuilder.create()
                .setDefaultRequestConfig(config)
                .build();

        ipList.forEach(ip -> executor.submit(() -> {
            try {
                final HttpGet httpget = new HttpGet(StringUtils.replace(url, "{ip}", ip));

                CloseableHttpResponse execute = client.execute(httpget);
                String string = execute.getEntity().toString();
                execute.close();

                System.out.println(ip);
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }));

        TimeUnit.SECONDS.sleep(5000);*/
    }

}
